import React, { Component } from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { HashRouter } from 'react-router-dom';
import Pages from './pages/index';
import { antdThemes, packageThemes, LanguagePackage } from '@/utils/createContext';
import configureStore from './store/configureStore';
import {LocaleProvider} from 'antd'

import './assets/scss/index.scss';

let store = configureStore();

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      currentPackageThemes: packageThemes['zh-CN'],
      currentAntdThemes: antdThemes['zh-CN']
    };
  }
  componentDidMount() {
    const currentLanguage = window.__currentLanguage || 'zh-CN';
    this.setState({
      currentPackageThemes: {...packageThemes[currentLanguage]},
      currentAntdThemes: {...antdThemes[currentLanguage]},
    });
  }

  render() {
    const { currentAntdThemes, currentPackageThemes } = this.state;
    return (
      <LocaleProvider locale={currentAntdThemes}>
        <LanguagePackage.Provider value={currentPackageThemes}>
          <Provider store={store}>
            <HashRouter>
              <React.Fragment>
                <Pages />
              </React.Fragment>
            </HashRouter>
          </Provider>
        </LanguagePackage.Provider>
      </LocaleProvider>
    );
  }
};

render(
  <App />,
  document.querySelector('#app')
);
